package com.alangyun.remind.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alangyun.remind.repository.StoreEngine;
import com.alangyun.remind.repository.StoreEngine.ImportInfo;
import com.alangyun.remind.repository.data.LeaderDataset;
import com.alangyun.remind.repository.data.OrganDataset;
import com.alangyun.remind.repository.data.TalentDataset;

@Controller
public class HomeController extends AbstractController {

	@RequestMapping(value = { Paths.ROOT, Paths.INDEX }, method = { RequestMethod.GET, RequestMethod.POST })
	public String homePage(Model model) {
		List<ImportInfo> list = StoreEngine.getHistory();
		if(list!=null && list.size()>0) {
			for(ImportInfo item: list) {
				if(LeaderDataset.class.getSimpleName().toLowerCase().equals(item.getName()))
					item.setName("干部预警数据 - 导入日志");
				else if(TalentDataset.class.getSimpleName().toLowerCase().equals(item.getName()))
					item.setName("人才开发预警 - 导入日志");
				else if(OrganDataset.class.getSimpleName().toLowerCase().equals(item.getName()))
					item.setName("劳动组织预警 - 导入日志");
				else
					item.setName("员工预警数据 - 导入日志");
			}
		}
		
		model.addAttribute("history", list);
		
		return "/mind/index";
	}
	
	@GetMapping(Paths.ERROR)
	public String homePage() {
		return "/mind/page-error";
	}
}
